package com.hx.likeserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.common.vo.Result;
import com.hx.likeserver.entity.Like;
import com.hx.likeserver.mapper.LikeMapper;
import com.hx.likeserver.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LikeServiceImpl extends ServiceImpl<LikeMapper, Like> implements LikeService {

    @Autowired
    private LikeMapper likeMapper;

    @Override
    public boolean save1(Like like){
        QueryWrapper<Like> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",like.getUserId());
        List<Like> like1 = likeMapper.selectList(queryWrapper);
        for (int i=0;i<like1.size();i++){
            if (like1.get(i).getMusicId()==like.getMusicId()){
                System.out.println("重复收藏");
                return false;
            }
        }
        System.out.printf("收藏成功");
        return true;
    }

    @Override
    public List<Like> findLikeByUser(Integer userId) {
        return likeMapper.findLikeByUser(userId);
    }
}
